#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QMouseEvent>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //创建自定义Label
    label =new Label(this);
    label->setText("点击按钮，获取鼠标位置");
    label->setGeometry(100,100,500,400);
    label->setFrameShape(QFrame::Box);

    //开启跟踪鼠标位置
    this->setMouseTracking(true);

    //初始化鼠标滚轮滚动事件的总距离
    total=0;
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<<"鼠标位置: x:"<<event->x()<<", "<<event->y();
}

void Widget::wheelEvent(QWheelEvent *event)
{
    total+=event->delta();
    qDebug()<<total;
}

